package com.eric.rabbitmq.direct;

import com.eric.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.util.Scanner;

public class EmitLog {
    public static final String EXCHANGE_NAME = "direct_logs";
    public static final String ROUTING_KEY = "info";//info or error

    public static void main(String[] args) throws Exception{
        //声明信道
        Channel channel = RabbitMqUtils.getChannel();
        //声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME,  BuiltinExchangeType.DIRECT);
       //输入消息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
            channel.basicPublish(EXCHANGE_NAME,ROUTING_KEY,null,message.getBytes("UTF-8"));
            System.out.println("发送消息："+ message);
        }
    }
}
